/*
Copyright(c) 2008 Jari Kemppinen <jari@viddem.com>

This example was built upon the PureMVC Framework by Cliff Hall.
http://www.puremvc.org
This example uses the Java PureMVC Framework Version 0.2

Please contribute to the PureMVC community.

License
-------
Your reuse is governed by the Creative Commons Attribution 3.0 license.
 */

package org.lbroussal.client;

import org.lbroussal.client.controller.MyCommandProvider;
import org.lbroussal.client.controller.ProcessLogin;
import org.lbroussal.client.controller.StartupCommand;
import org.lbroussal.client.controller.ProcessLogout;
import org.lbroussal.client.model.ItemDataProxy;
import org.lbroussal.client.model.UserDataProxy;
import org.puremvc4gwt.client.patterns.facade.Facade;
import org.puremvc4gwt.client.patterns.observer.Notification;

public class ApplicationFacade extends Facade {

    public static final String STARTUP = "startup";

    public static final String LOGIN = "login";

    public static final String PROCESS_LOGIN = "processLogin";

    public static final String PROCESS_LOGOUT = "processLogout";

    public static final String LOGIN_SUCCESSFUL = "loginSuccessful";

    public static final String LOGIN_FAIL = "loginFail";

    public static final String MAIN = "main";

    // Startup command notifications
    public static final String PREP_MODEL = "prepModel";

    public static final String PREP_VIEW = "prepView";


    public static PureMVC4GWTLoginDemo loginDemo;

    public static ApplicationFacade getInst() {
        if (instance == null) {
            instance = new ApplicationFacade();
            instance.registerCommandProvider(new MyCommandProvider());
        }

        return (ApplicationFacade)instance;
    }

    protected void initializeController() {
        super.initializeController();
 
        registerCommand(STARTUP, StartupCommand.class);
        registerCommand(PROCESS_LOGIN, ProcessLogin.class);
        registerCommand(PROCESS_LOGOUT, ProcessLogout.class);
    }

    public void start(PureMVC4GWTLoginDemo _projectTracker) {
        ApplicationFacade.loginDemo = _projectTracker;
        this.notifyObservers(new Notification(STARTUP, null, null));
    }

    /**
     * Typed accessors for data scopes/proxys.
     */
    public ItemDataProxy getItemDataScope() {
        return (ItemDataProxy)retrieveProxy(ItemDataProxy.NAME);
    }

    public UserDataProxy getUserDataScope() {
        return (UserDataProxy)retrieveProxy(UserDataProxy.NAME);
    }
}